import { observable, action } from "mobx";
import { Toast, Tools } from "weaver-mobile";
import { Reply } from "weaver-mobile-page";
import { SupStore } from "../supStore.js";
import * as Apis from "../../apis/govern";
const getLabel = Tools.getLabel;
/*
 * @info: EditStore
 * @Author: lusx
 * @Date: 2019-12-01 11:13:16
 * @Last modified by:   lusx
 * @Last modified time: 01-04-2019 04:05:41
 */
export default class EditStore {
  @observable replyStore = new Reply.Store({
    getAttachList: this.getAttachList,
    getAtConfig: this.getAtConfig
  });
  @observable routePath = null;
  @observable sliderValue = 0;
  getAttachList = () =>
    new Promise(resolve => {
      resolve({
        attachList: [
          {
            key: "flow", // 字符串
            type: "browser",
            path: `${this.routePath}/browser`,
            config: {
              type: 16,
              isSingle: false,
              hasAdvanceSerach: true
            },
            iconType: "flow",
            iconBgColor: "#61A8F5",
            text: "流程",
            model: 2 // model(模式) 1: 常规模式， 2: 编辑模式（不显示小红点）
          },
          {
            key: "doc",
            type: "browser",
            path: `${this.routePath}/browser`,
            config: {
              type: 9,
              isSingle: false,
              hasAdvanceSerach: true
            },
            iconType: "file",
            iconBgColor: "#F3B04C",
            text: "文档",
            model: 2
          },
          {
            config: {
              isSingle: false,
              hasAdvanceSerach: true,
              type: "workplan"
            },
            iconBgColor: "#61A8F5",
            iconType: "task",
            key: "workplan",
            model: 2,
            path: `${this.routePath}/browser`,
            text: "日程",
            type: "browser"
          },
          // {
          //   key: "file",
          //   type: "upload",
          //   path: "/myBlog/blog/writeMyBlog/upload",
          //   config: {
          //     multiSelection: true
          //   },
          //   iconType: "file",
          //   iconBgColor: "#F3B04C",
          //   text: "附件",
          //   model: 2
          // },
          {
            config: {
              uploadUrl: "/api/blog/base/uploadDoc",
              maxSize: "0",
              position: "105",
              multiSelection: true
            },
            iconBgColor: "#F3B04C",
            iconType: "file",
            key: "uploadFile",
            model: 2,
            path: "/upload",
            text: "附件",
            type: "upload"
          }
        ]
      });
    });

  getAtConfig = () =>
    new Promise(resolve => {
      resolve({
        atConfig: {
          key: "at",
          path: `${this.routePath}`,
          config: {
            type: 16,
            isSingle: false
          }
        }
      });
    });
  constructor(props) {
    //super(props)
    this.initDatas = this.initDatas.bind(this);
    this.publishComment = this.publishComment.bind(this);
    this.publishReport = this.publishReport.bind(this);
  }
  @action
  setRoutePath = pathname => {
    this.routePath = pathname;
  };
  /**
   * 初始化方法
   * @method initDatas
   * @for InfoStore
   * @param {参数类型} {"id":String} 参数说明  列表每行id;
   * @return {返回值类型}
   */
  @action
  initDatas(params) {}
  //发布评论
  publishComment = (params, callback = false) => {
    if (params.hasOwnProperty("content") && params.content.length > 0) {
      Toast.loading(getLabel("384534","正在提交中..."), 20);
      //params.content = params.content.replace(GetRegex("wrap"), "");

      Apis.saveInstruct(params).then(result => {

        if (result.status === "1") {
          Toast.hide();
          Toast.success(getLabel("83885","操作成功！"));
          callback ? callback(result) : null;
        } else if (result.status === "-3") {
          Toast.hide();
          Toast.info(result.error);
        } else {
          Toast.hide();
          Toast.fail(getLabel("384535","提交失败！"));
        }
      });
    } else {
      Toast.fail(getLabel("126982","请填写内容"));
    }
  };
  //发布汇报
  publishReport(params, callback = false) {
    if (params.hasOwnProperty("content") && params.content.length > 0) {
      Toast.loading(getLabel("384534","正在提交中..."), 20);
      Apis.reportTask(params).then(result => {
        if (result.status === "1") {
          this.sliderValue = params.progress;
          Toast.hide();
          Toast.success(getLabel("83885","操作成功！"));
          callback ? callback(result) : null;
        } else if (result.status === "-1") {
          Toast.hide();
          Toast.info(result.error);
        } else if (result.status === "-3") {
          Toast.hide();
          Toast.info(result.error);
        } else {
          Toast.hide();
          Toast.fail(getLabel("384535","提交失败！"));
        }
      });
    } else {
      Toast.fail(getLabel("126982","请填写内容"));
    }
  }
  //清空
  @action
  clearState(callback) {
    // this.form.resetFields();
    // this.refreshing = false;
    // this.pathname = '';
  }
}
